package com.hxgis.web.controller;

import com.hxgis.common.base.ResultVO;
import com.hxgis.common.parms.RangeParm;
import com.hxgis.common.service.RainHourService;
import com.hxgis.common.utils.ResultVOUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 小数数据
 */
@RestController
@RequestMapping("/hour")
@Slf4j
@Api(tags = "rain-hour")
public class RainHoursController {

    @Autowired
    private RainHourService rainHoursService;


    @ApiOperation(value="从cimiss将小时降雨事件导入小时降水表按照年批量", notes="startYear：1951，endYear：2019")
    @GetMapping("/saveByYear")
    public ResultVO saveByYear(@RequestParam("startYear") Integer startYear, @RequestParam("endYear") Integer endYear) {
        rainHoursService.saveRainHoursByYear(startYear,endYear);
        return ResultVOUtil.success("sucess");
    }



    @ApiOperation(value="根据时间导入小时降水数据",  notes="startTime：2020061100，endTime：2020061106")
    @GetMapping("/save")
    public ResultVO saveRainHours(@RequestParam("startTime") String startTime,
                                  @RequestParam("endTime") String endTime) {

        return ResultVOUtil.success(rainHoursService.saveRainHours(startTime,endTime));
    }



    @ApiOperation(value="查询时间段数据",  notes="startTime：2020061100，endTime：2020061106")
    @GetMapping("/query")
    public ResultVO queryRainHours(@RequestParam("startTime") String startTime,
                                   @RequestParam("endTime") String endTime,
                                   @RequestParam(value = "stationNo",required = false) String stationNo,
                                   @RequestParam(value = "threadSize") Integer threadSize) {

        return ResultVOUtil.success(rainHoursService.queryRainHours(startTime,endTime,stationNo,threadSize));
    }

    @ApiOperation(value="查询任意时段降水累计值",  notes="startTime：2020061100，endTime：2020061106")
    @GetMapping("/query/sum")
    public ResultVO rainHourSum(@RequestParam("startTime") String startTime,
                                   @RequestParam("endTime") String endTime,
                                   @RequestParam(value = "stationNo",required = false) String stationNo) {

        return ResultVOUtil.success(rainHoursService.queryHourAnaByTimeRange(startTime,endTime,stationNo));
    }


    @ApiOperation(value="区间分组",  notes="startTime：2020061100，endTime：2020061106")
    @PostMapping("/range/group")
    public ResultVO rangeGroup(@RequestParam("startTime") String startTime,
                                @RequestParam("endTime") String endTime,
                               @RequestBody List<RangeParm> rangeParms) {

        return ResultVOUtil.success(rainHoursService.rangeGroup(startTime,endTime,rangeParms));
    }


    /**
     * 小时降水色斑以及色斑图
     * @param startTime
     * @param endTime
     * @param flag 1:查看色斑 2 色斑图下载
     * @return
     */
    @GetMapping("/queryGeoJson")
    public String queryGeoJson(@RequestParam("startTime") String startTime,
                               @RequestParam("endTime") String endTime,
                               @RequestParam("flag") String flag,
                                 HttpServletResponse response) {
        return rainHoursService.queryGeoJson(startTime, endTime, flag, response);
//        return ResultVOUtil.success(rainHoursService.queryGeoJson(startTime, endTime, flag, response));
    }


}
